﻿using Project.DAL;
using Project.DAL.information;
using Project.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Project.BLL.information
{
    public class storeBll : BaseBLL<store>
    {
        public override void SetDal()
        {
         Dal=new StoreDal();
        }
        //分页显示店铺信息
        public List<store> GetStoresByPage(int page, int size, string name, out int count)
        {
            var list = base.Query();
            if(!string.IsNullOrEmpty(name))
            {
                list=list.Where(u=>u.store_name.Contains(name));
            }
            count = list.Count();
            var data=list.OrderBy(u=>u.store_id).Skip((page-1)* size).Take(size);
            return data.ToList();

        }

        //删除
        public bool Del(int id) {
            var data = Dal.Query().Where(x => x.store_id == id).FirstOrDefault();
            if(data != null)
            {
                Dal.Delete(data);
                return Dal.SaveChanges();
            }
            else
            {
                return false;
            }

        }

        //批量删除
        public bool Del(int[] ids)
        {
            var data=Dal.Query().Where(x=>ids.Contains(x.store_id)).ToList();
            if(data != null)
            {
                Dal.Delete(data);
                return Dal.SaveChanges();
                 
            }
            else
            {
                return false;
            }
        }
    }

    internal class StoreDal : BaseDAL<store>
    {
    }
}
